bitkeeper revision 1.1041.18.1 (40ec37bbEfVooGtkbbrgCf3ZWEhJEg)
authorkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Wed, 7 Jul 2004 17:49:47 +0000 (17:49 +0000)
committerkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Wed, 7 Jul 2004 17:49:47 +0000 (17:49 +0000)
More x86_64 stuff. Now links, but a bunch of stuff is stubbed out.
Will it run? :-)

xen/arch/x86/Makefile
xen/arch/x86/Rules.mk
xen/arch/x86/boot/x86_64.S
xen/arch/x86/trampoline.S
xen/arch/x86/x86_64/xen.lds
xen/common/Makefile
xen/drivers/acpi/Makefile
xen/drivers/char/Makefile
xen/drivers/pci/Makefile
xen/include/asm-x86/system.h

index 039df504ef9b51b13afb9e118407453c10a84066..1290f0420f37ebddf62dacdff335b8b7b7fe2c34 100644 (file)
@@ -9,8 +9,15 @@ endif
 OBJS += $(patsubst %.S,%.o,$(wildcard $(TARGET_SUBARCH)/*.S))
 OBJS += $(patsubst %.c,%.o,$(wildcard $(TARGET_SUBARCH)/*.c))
 
+ifeq ($(TARGET_SUBARCH),x86_32)
 LINK_BASE := 0xFC500000 # Xen is linked here
 LOAD_BASE := 0x00100000 # Xen is loaded here
+endif
+
+ifeq ($(TARGET_SUBARCH),x86_64)
+LINK_BASE := 0xFFFF830000100000 # Xen is linked here
+LOAD_BASE := 0x0000000000100000 # Xen is loaded here
+endif
 
 # What happens here? We link object files together, starting at LINK_BASE
 # (a very high address). But the bootloader cannot put things there, so we
@@ -19,8 +26,9 @@ LOAD_BASE := 0x00100000 # Xen is loaded here
 # (NB. Linux gets round this by turning its image into raw binary, then 
 # wrapping that with a low-memory bootstrapper.)
 default: boot/$(TARGET_SUBARCH).o $(OBJS)
-       $(LD) -r -o arch.o $(OBJS)
-       $(LD) $(LDFLAGS) boot/$(TARGET_SUBARCH).o $(ALL_OBJS) -o $(TARGET)-syms
+       $(LD) $(LDFLAGS) -r -o arch.o $(OBJS)
+       $(LD) $(LDFLAGS) -T $(TARGET_SUBARCH)/xen.lds -N \
+           boot/$(TARGET_SUBARCH).o $(ALL_OBJS) -o $(TARGET)-syms
        objcopy -R .note -R .comment -S $(TARGET)-syms $(TARGET)
        $(BASEDIR)/tools/elf-reloc $(LINK_BASE) $(LOAD_BASE) $(TARGET)
 
index 560b381845afdd6587db6bc36915032c44b5a2af..2ecca1fffed8470a22fc08b501a99da2487de347 100644 (file)
@@ -5,17 +5,16 @@ CC := gcc
 LD := ld
 
 CFLAGS  := -nostdinc -fno-builtin -fno-common -fno-strict-aliasing -O3
-CFLAGS  += -iwithprefix include -Wall -Werror -fomit-frame-pointer
+CFLAGS  += -iwithprefix include -Wall -Werror -fomit-frame-pointer -pipe
 CFLAGS  += -I$(BASEDIR)/include -Wno-pointer-arith -Wredundant-decls
 
-LDFLAGS := -T $(TARGET_SUBARCH)/xen.lds -N 
-
 ifeq ($(TARGET_SUBARCH),x86_32)
-CFLAGS += -m32 -march=i686
-LDARCHFLAGS := --oformat elf32-i386 
+CFLAGS  += -m32 -march=i686
+LDFLAGS := --oformat elf32-i386 
 endif
 
 ifeq ($(TARGET_SUBARCH),x86_64)
-CFLAGS += -m64
-LDARCHFLAGS := --oformat elf64-x86-64
+CFLAGS  += -m64 -mno-red-zone -fpic -fno-reorder-blocks
+CFLAGS  += -fno-asynchronous-unwind-tables
+LDFLAGS := --oformat elf64-x86-64
 endif
index 46af44607cd987c172fc82aea2af875d710d384b..ab5219f64c2e0643613eacc95a455cc858cd1e03 100644 (file)
@@ -9,9 +9,8 @@
         
 ENTRY(start)
         jmp __start
-
-        .align 4
-
+        
+        .org    0x004
 /*** MULTIBOOT HEADER ****/
         /* Magic number indicating a Multiboot header. */
        .long   0x1BADB002
@@ -19,11 +18,11 @@ ENTRY(start)
        .long   0x00000002
        /* Checksum: must be the negated sum of the first two fields. */
        .long   -0x1BADB004
-        
-bad_cpu_msg:
+
+        .org    0x010
         .asciz "Bad CPU: does not support 64-bit (long) mode."
 bad_cpu:
-        mov     $SYMBOL_NAME(bad_cpu_msg)-__PAGE_OFFSET,%esi
+        mov     $0x100010,%esi # Error message
         mov     $0xB8000,%edi  # VGA framebuffer
 1:      mov     (%esi),%bl
         test    %bl,%bl        # Terminate on '\0' sentinel
@@ -41,19 +40,14 @@ bad_cpu:
         jmp     1b
         
 __start:
+        cld
+        cli
+
         /* Set up a few descriptors: on entry only CS is guaranteed good. */
-        lgdt    %cs:nopaging_gdt_descr-__PAGE_OFFSET
+        lgdt    %cs:0x1001f0
         mov     $(__HYPERVISOR_DS),%ecx
         mov     %ecx,%ds
         mov     %ecx,%es
-        mov     %ecx,%fs
-        mov     %ecx,%gs
-        ljmp    $(__HYPERVISOR_CS32),$(1f)-__PAGE_OFFSET
-1:      lss     stack_start-__PAGE_OFFSET,%esp
-
-        /* Reset EFLAGS (subsumes CLI and CLD). */
-       pushl   $0
-       popf
 
         /* We begin by interrogating the CPU for the presence of long mode. */
         mov     $0x80000000,%eax
@@ -68,74 +62,93 @@ __start:
         /* Set up FPU. */
         fninit
         
-        /* Set up CR4, except global flag which Intel requires should be     */
-        /* left until after paging is enabled (IA32 Manual Vol. 3, Sec. 2.5) */
-        mov     mmu_cr4_features-__PAGE_OFFSET,%ecx
-        and     $0x7f,%cl   # CR4.PGE (global enable)
+        /* Enable PAE in CR4. */
+        mov     $0x20,%ecx # X86_CR4_PAE
         mov     %ecx,%cr4
-               
+
         cmp     $(SECONDARY_CPU_FLAG),%ebx
         je      start_paging
 
-       add     $__PAGE_OFFSET,%ebx
-        push    %ebx /* Multiboot info struct */
-        push    %eax /* Multiboot magic value */
-
-        /* Initialize BSS (no nasty surprises!) */
-        mov     $__bss_start-__PAGE_OFFSET,%edi
-        mov     $_end-__PAGE_OFFSET,%ecx
-        sub     %edi,%ecx
-        xor     %eax,%eax
-        rep     stosb
-
-        /* Initialize low and high mappings of all memory with 4MB pages */
-        mov     $idle_pg_table-__PAGE_OFFSET,%edi
-        mov     $0x1e3,%eax                  /* PRESENT+RW+A+D+4MB+GLOBAL */
-1:      mov     %eax,__PAGE_OFFSET>>20(%edi) /* high mapping */
-        stosl                                /* low mapping */
-        add     $(1<<L2_PAGETABLE_SHIFT),%eax
-        cmp     $DIRECTMAP_PHYS_END+0x1e3,%eax
-        jne     1b
+        mov     %ebx,0x1001e0 /* Multiboot info struct */
+        mov     %eax,0x1001e4 /* Multiboot magic value */
 
-        /* Initialise IDT with simple error defaults. */
-        lea     ignore_int,%edx
-        mov     $(__HYPERVISOR_CS64 << 16),%eax
-        mov     %dx,%ax            /* selector = 0x0010 = cs */
-        mov     $0x8E00,%dx        /* interrupt gate - dpl=0, present */
-        lea     SYMBOL_NAME(idt_table)-__PAGE_OFFSET,%edi
-        mov     $256,%ecx
-1:      mov     %eax,(%edi)
-        mov     %edx,4(%edi)
-        add     $8,%edi
+        /* Initialize mappings of 1GB of memory. */
+        mov     $0x103000,%edi               /* idle_pg_table_l2 */
+        mov     $0x1e3,%eax                  /* PRESENT+RW+A+D+PSE+GLOBAL */
+        mov     $512,%ecx
+1:      stosl
+        add     $0x200000,%eax
         loop    1b
 
 start_paging:
-        mov     $idle_pg_table-__PAGE_OFFSET,%eax
+        mov     $0x101000,%eax   /* idle_pg_table */
         mov     %eax,%cr3
         mov     $0x80050033,%eax /* hi-to-lo: PG,AM,WP,NE,ET,MP,PE */
         mov     %eax,%cr0
         jmp     1f
 1:      /* Now in compatibility mode. Long-jump into 64-bit mode. */
-        ljmp    $(__HYPERVISOR_CS64),$1f
+        ljmp    $(__HYPERVISOR_CS64),$0x1000e0
 
         .code64
-1:      /* Install relocated selectors (FS/GS unused). */
-        lgdt    gdt_descr
+        .org    0x00e0
+
+        /* Jump to high mappings. */
+        mov     high_start(%rip),%rax
+        push    %rax
+        ret
+__high_start:
+        
+        /* Install relocated selectors (FS/GS unused). */
+        lgdt    gdt_descr(%rip)
         mov     $(__HYPERVISOR_DS),%ecx
         mov     %ecx,%ds
         mov     %ecx,%es
         mov     %ecx,%ss
-1:      /* Paging enabled, so we can now enable GLOBAL mappings in CR4. */
-        mov     mmu_cr4_features,%rcx
+
+        /* Enable full CR4 features. */
+        mov     mmu_cr4_features(%rip),%rcx
         mov     %rcx,%cr4
-        /* Relocate ESP */
-        add     $__PAGE_OFFSET,%esp
 
-        lidt    idt_descr
+        mov     stack_start(%rip),%rsp
+        
+        /* Reset EFLAGS (subsumes CLI and CLD). */
+       pushq   $0
+       popf
+
+        lidt    idt_descr(%rip)
                 
         cmp     $(SECONDARY_CPU_FLAG),%ebx
         je      start_secondary
 
+        /* Initialize BSS (no nasty surprises!) */
+        lea     __bss_start(%rip),%rdi
+        lea     _end(%rip),%rcx
+        sub     %rdi,%rcx
+        xor     %rax,%rax
+        rep     stosb
+
+        /* Initialise IDT with simple error defaults. */
+        lea     ignore_int(%rip),%rdx
+        mov     $(__HYPERVISOR_CS64 << 16),%eax
+        mov     %dx,%ax            /* selector = 0x0010 = cs */
+        mov     $0x8E00,%dx        /* interrupt gate - dpl=0, present */
+        lea     idt_table(%rip),%rdi
+        mov     $256,%rcx
+1:      mov     %eax,(%rdi)
+        mov     %edx,4(%rdi)
+        add     $8,%rdi
+        loop    1b
+
+        xor     %rax,%rax
+        mov     0x1001e0,%eax /* Multiboot info struct */
+        lea     start(%rip),%rbx
+        sub     $0x100000,%rbx
+        add     %rbx,%rax
+        push    %rax
+        xor     %rax,%rax
+        mov     0x1001e4,%eax /* Multiboot magic value */
+        push    %rax
+        
         /* Call into main C routine. This should never return.*/
                call    cmain
         ud2     /* Force a panic (invalid opcode). */
@@ -148,42 +161,23 @@ ignore_int:
         mov     $(__HYPERVISOR_DS),%eax
         mov     %eax,%ds
         mov     %eax,%es
-        pushq   $int_msg
+        lea     int_msg(%rip),%rax
+        push    %rax
         call    SYMBOL_NAME(printf)
 1:      jmp     1b
 
         .code32
-        .align 8
                 
-/*** STACK LOCATION ***/
-        
-ENTRY(stack_start)
-        .long SYMBOL_NAME(cpu0_stack) + 8100 - __PAGE_OFFSET
-        .long __HYPERVISOR_DS
-        
 /*** DESCRIPTOR TABLES ***/
 
 .globl SYMBOL_NAME(idt)
 .globl SYMBOL_NAME(gdt)        
 
-        .word   0    
-idt_descr:
-       .word   256*8-1
-SYMBOL_NAME(idt):
-        .long  SYMBOL_NAME(idt_table)
-
-        .word   0
-gdt_descr:
-       .word   (LAST_RESERVED_GDT_ENTRY*8)+7
-SYMBOL_NAME(gdt):       
-        .long   SYMBOL_NAME(gdt_table) /* gdt base */
-
-        .word   0
-nopaging_gdt_descr:
+        .org    0x1f0
         .word   (LAST_RESERVED_GDT_ENTRY*8)+7
-        .long   SYMBOL_NAME(gdt_table)-__PAGE_OFFSET
+        .long   0x100200 # gdt_table
         
-        .align 64
+        .org    0x200
 ENTRY(gdt_table)
         .fill FIRST_RESERVED_GDT_ENTRY,8,0
         .quad 0x0000000000000000     /* unused */
@@ -193,13 +187,76 @@ ENTRY(gdt_table)
         .quad 0x00cffa000000ffff     /* 0x0823 ring 3 code, compatibility */
         .quad 0x00affa000000ffff     /* 0x082b ring 3 code, 64-bit mode   */
         .quad 0x00cff2000000ffff     /* 0x0833 ring 3 data                */
-        .quad 0x0000000000000000     /* unused                           */
-        .fill 2*NR_CPUS,8,0          /* space for TSS and LDT per CPU    */
+        .quad 0x0000000000000000     /* unused                            */
+        .fill 2*NR_CPUS,8,0          /* space for TSS and LDT per CPU     */
+
+        .word   0
+gdt_descr:
+       .word   (LAST_RESERVED_GDT_ENTRY*8)+7
+SYMBOL_NAME(gdt):       
+        .quad   SYMBOL_NAME(gdt_table)
+
+        .word   0    
+idt_descr:
+       .word   256*8-1
+SYMBOL_NAME(idt):
+        .quad  SYMBOL_NAME(idt_table)
 
+ENTRY(stack_start)
+        .quad   SYMBOL_NAME(cpu0_stack) + 8100 - __PAGE_OFFSET
+
+high_start:
+        .quad   __high_start
+                
         .org 0x1000
-ENTRY(idle_pg_table) # Initial page directory is 4kB
+ENTRY(idle_pg_table)
+ENTRY(idle_pg_table_4)
+        .quad 0x0000000000102007 # PML4[0]
+        .fill 261,8,0
+        .quad 0x0000000000102007 # PML4[262]
         .org 0x2000
-ENTRY(cpu0_stack)    # Initial stack is 8kB
+ENTRY(idle_pg_table_l3)
+        .quad 0x0000000000103007
+        .org 0x3000
+ENTRY(idle_pg_table_l2)
         .org 0x4000
+ENTRY(cpu0_stack)    # Initial stack is 8kB
+        .org 0x6000
 ENTRY(stext)
 ENTRY(_stext)
+
+.globl map_domain_mem, unmap_domain_mem, ret_from_intr
+map_domain_mem:
+unmap_domain_mem:
+ret_from_intr:
+#undef machine_to_phys_mapping
+.globl copy_to_user, set_intr_gate, die, machine_to_phys_mapping
+copy_to_user:
+set_intr_gate:
+die:
+machine_to_phys_mapping:
+.globl copy_from_user, show_registers, __set_fixmap, do_iopl, check_descriptor
+copy_from_user: 
+show_registers: 
+__set_fixmap: 
+do_iopl: 
+check_descriptor:
+.globl set_gdt, idt_table, copy_user_generic, memcmp, idt_tables, new_thread
+set_gdt:
+idt_table:
+copy_user_generic:
+memcmp:
+idt_tables:
+new_thread:
+.globl switch_to, continue_nonidle_task, __get_user_1, paging_init, trap_init
+switch_to:
+continue_nonidle_task:
+__get_user_1:
+paging_init:
+trap_init: 
+.globl __get_user_8, zap_low_mappings, set_debugreg
+__get_user_8:
+zap_low_mappings:
+set_debugreg:
+        
+        
index 02018f347a7f5bb7aa2d7557f0c44e1ebfb6fa53..d625a475580eea44614d4b5b15221116b1da4cbd 100644 (file)
@@ -55,8 +55,12 @@ idt_48:
 
 gdt_48:
        .word   (LAST_RESERVED_GDT_ENTRY*8)+7
+#ifdef __i386__
        .long   gdt_table-__PAGE_OFFSET
-
+#else
+       .long   0x100200 # gdt_table
+#endif
+        
 .globl SYMBOL_NAME(trampoline_end)
 SYMBOL_NAME_LABEL(trampoline_end)
 
index caea240e5298dc5cadbd593273e5463d4a431e44..d189a27e03b7587f4483728ac485ccdd5f8f0c1d 100644 (file)
@@ -4,7 +4,7 @@ OUTPUT_ARCH(i386:x86-64)
 ENTRY(start)
 SECTIONS
 {
-  . = 0xFFFF840000100000;
+  . = 0xFFFF830000100000;
   _text = .;                   /* Text and read-only data */
   .text : {
        *(.text)
index 34febca43eb064ff19984f717616c61908e77480..830418019883dc0236a1bd5d9856601f80e10bf9 100644 (file)
@@ -15,7 +15,7 @@ OBJS := $(subst trace.o,,$(OBJS))
 endif
 
 default: $(OBJS)
-       $(LD) $(LDARCHFLAGS) -r -o common.o $(OBJS)
+       $(LD) $(LDFLAGS) -r -o common.o $(OBJS)
 
 clean:
        rm -f *.o *~ core
index 3e10aba0736891d78118cc917c22359b1ef6280f..2b80430148b70f9d699dba354899ba7729703368 100644 (file)
@@ -7,7 +7,7 @@ include $(BASEDIR)/Rules.mk
 OBJS := acpi_ksyms.o tables.o
 
 default: $(OBJS)
-       $(LD) -r -o driver.o $(OBJS)
+       $(LD) $(LDFLAGS) -r -o driver.o $(OBJS)
 
 clean:
        rm -f *.o *~ core
index 574b7d2d79301e69e3ba0129527eb5a328d4da82..f938f870173575f8ba76454fc7ab2e6644e894f8 100644 (file)
@@ -2,7 +2,7 @@
 include $(BASEDIR)/Rules.mk
 
 default: $(OBJS)
-       $(LD) -r -o driver.o $(OBJS)
+       $(LD) $(LDFLAGS) -r -o driver.o $(OBJS)
 
 clean:
        rm -f *.o *~ core
index 1d811d45e3011ccf030f671062f0780fb6b2ff40..7fd6c1705fc3ca9d0e31675d0ae438145436da05 100644 (file)
@@ -29,7 +29,7 @@ OBJS := pci.o quirks.o compat.o names.o setup-res.o
 #endif
 
 default: $(OBJS)
-       $(LD) -r -o driver.o $(OBJS)
+       $(LD) $(LDFLAGS) -r -o driver.o $(OBJS)
 
 clean:
        rm -f *.o *~ core gen-devlist classlist.h devlist.h
index b854d1b0580bc4e6b98e2f67dbed341b85ff44a8..ff88ed46922159ffbaecad2629e215db48b40c46 100644 (file)
@@ -131,6 +131,7 @@ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
  * If no fault occurs then _o is updated to teh value we saw at _p. If this
  * is the same as the initial value of _o then _n is written to location _p.
  */
+#ifdef __i386__
 #define cmpxchg_user(_p,_o,_n)                                          \
 ({                                                                      \
     int _rc;                                                            \
@@ -150,6 +151,9 @@ static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
         : "memory");                                                    \
     _rc;                                                                \
 })
+#else
+#define cmpxchg_user(_p,_o,_n) ({ __asm__ __volatile__ ( "" : : "r" (_p), "r" (_o), "r" (_n) ); BUG(); 0; })
+#endif
 
 /*
  * Force strict CPU ordering.